package com.ly.reserveconsumer.controller;


import com.alibaba.fastjson.JSONObject;
import com.ly.reserveconsumer.service.FoodInformationService;
import com.ly.reserveconsumer.service.merchantsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class MerchantsController {

    @Autowired
    merchantsService ms;
    @Autowired
    FoodInformationService fts;


    /**
     * 登录入口
     *商家登录验证
     * @param merchants
     * @return
     */
    @RequestMapping("/login")
    public String merchantsCount(@RequestParam Map map, Model model, HttpServletRequest request ){

        //测试是否查询到用户登录
        System.out.println(ms.merchantsCount(map));

        if(ms.merchantsCount(map)!=null){
            JSONObject JSONPObject = JSONObject.parseObject(ms.merchantsCount(map));
            HttpSession session = request.getSession();
            session.setAttribute("user",JSONPObject);
            model.addAttribute("list",fts.findFoodInfo(map));
            return "list";
         }
        return "login";
    }


}
